{%extends "admin/base.html" %}

{%block main%}
<div class="row">
    <div class="col-12">
        <form class="form-horizontal">
            <div class="card">
                <div class="card-header d-flex p-0">
                    <h3 class="card-title p-3">系统设置</h3>
                    {% include 'admin/system/config/tab.html' %}
                </div>
                <div class="card-body">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="form-group row">
                                <label for="admin_name" class="col-sm-2 col-form-label">管理程序名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="admin_name" name="admin_name" value="{{ info.admin_name }}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="admin_version" class="col-sm-2 col-form-label">管理程序版本号</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="admin_version" name="admin_version" value="{{ info.admin_version }}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="admin_version" class="col-sm-2 col-form-label">上传保存规则</label>
                                <div class="col-sm-10">
                                    <div class="icheck-warning d-inline">
                                        <input type="radio" id="upload_rule1" name="upload_rule" value="Y-m-d"{%if info.upload_rule == 'Y-m-d'%} checked{%endif%}>
                                        <label for="upload_rule1">年-月-日/文件名</label>
                                    </div>
                                    <div class="icheck-warning d-inline">
                                        <input type="radio" id="upload_rule2" name="upload_rule" value="Y-m/d"{%if info.upload_rule == 'Y-m/d'%} checked{%endif%}>
                                        <label for="upload_rule2">年-月/日/文件名</label>
                                    </div>
                                    <div class="icheck-warning d-inline">
                                        <input type="radio" id="upload_rule3" name="upload_rule" value="Y/m-d"{%if info.upload_rule == 'Y/m-d' or info.upload_rule == ''%} checked{%endif%}>
                                        <label for="upload_rule3">年/月-日/文件名</label>
                                    </div>
                                    <div class="icheck-warning d-inline">
                                        <input type="radio" id="upload_rule4" name="upload_rule" value="Y/m/d"{%if info.upload_rule == 'Y/m/d'%} checked{%endif%}>
                                        <label for="upload_rule4">年/月/日/文件名</label>
                                    </div>
                                    <span class="form-text text-danger">根据项目文件上传多寡，选择保存规则；文件将取内容的sha1散列作为文件名</span>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="admin_logo" class="col-sm-2 col-form-label">程序LOGO</label>
                                <div class="col-sm-10">
                                    {{ input_img('admin_logo', info.admin_logo)|raw }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-footer">
                    <button type="submit" class="btn btn-info">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
{%endblock%}

{%block js%}
<script>
    $(function () {
        $('form').submit(function (e) {
            e.preventDefault();
            $('form').find('button[type="submit"]').addClass('disabled');
            $.post('{{ url("") }}', $('form').serialize(), function (res) {
                _msg = ('msg' in res) ? res.msg : '未知错误';
                if (!('code' in res) || res.code != 0) {
                    toastr.error(_msg);
                } else {
                    toastr.success('保存成功');

                    setTimeout(() => {
                        window.location.reload();
                    }, 3000);
                }
                $('form').find('button[type="submit"]').removeClass('disabled');
            });
        });
    });
</script>
{%endblock%}